/*
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "./plotstats.h"

PlotStats::PlotStats()
{
  max   = 0;
  min   = 0;
  avg   = 0;
  std   = 0;
  sum   = 0;
  holes = 0;
}

PlotStats::PlotStats(QList<QPointF> data)
{
if(data.size() == 0)
  {
    max   = 0;
    min   = 0;
    avg   = 0;
    std   = 0;
    sum   = 0;
    holes = 0;
    return;
  }

  max = data.first().y();
  min = data.first().y();
  sum = 0;

  QPointF p;
  foreach(p, data)
  {
    if (p.x() > 1.0e20)
    {
      holes++;
    }
    else
    {
      double curVal = p.y();
      sum += curVal;

      if (curVal > max)
        max = curVal;
      if (curVal < min)
        min = curVal;
    }
  }

  avg = sum / (data.size() - holes);
}

double PlotStats::getMax()
{
  return max;
}

double PlotStats::getMin()
{
  return min;
}

double PlotStats::getAvg()
{
  return avg;
}

double PlotStats::getSum()
{
  return sum;
}

int PlotStats::getHoles()
{
  return holes;
}


